import axios from "axios";
import config from "@/util/config.js";

//创建一个axios的对象
const mdAPI = {
    mdBaseUrl: config.mdUrl+"/md",
    mdProMat: "/mat-pro",
    timeout: 5000,
    getMaterialAndProduct(param, callback) {
        axios.get(this.mdBaseUrl + this.mdProMat + "/query", {params: param}).then((res) => {
            callback(res.data);
        })
    },
    getMaterial(param, callback) {
        axios.get(this.mdBaseUrl + this.mdProMat + "/query/material", {params: param}).then((res) => {
            callback(res.data);
        })
    },
    getMatProClassify(callback) {
        axios.get(this.mdBaseUrl + this.mdProMat + "/classify/query").then((res) => {
            callback(res.data);
        })
    },
    //查询产品工单信息
    getProductOrders(param, callback) {
        axios.get(
            this.mdBaseUrl + this.mdProMat + "/query/order/" + param,
        ).then((res) => {
            callback(res.data);
        });
    },
    //查询产品工单信息
    getProductPlans(param, callback) {
        axios.get(
            this.mdBaseUrl + this.mdProMat + "/query/plan/" + param,
        ).then((res) => {
            callback(res.data);
        });
    },
    //修改产品状态
    updateProductStatus(param, callback) {
        axios.get(this.mdBaseUrl + this.mdProMat + "/update/status/" + param.id + "/" + param.status + "/" + param.category).then((res) => {
            callback(res.data);
        })
    },
    updateInventory(param, callback) {
        axios.get(this.mdBaseUrl + this.mdProMat + "/update/inventory/" + param.id + "/" + param.inventory + "/" + param.category).then((res) => {
            callback(res.data);
        })
    },
    //修改产品物料分类栏的分类信息
    updateProductClassify(param, callback) {
        axios.get(this.mdBaseUrl + this.mdProMat + "/classify/update/name?name=" + param.name + "&id=" + param.id).then((res) => {
            callback(res.data);
        })
    },
    //修改产品物料分类信息
    updateProductClassifyInfo(param, callback) {
        axios.get(this.mdBaseUrl + this.mdProMat + "/update/classify/" + param.id + "/" + param.classifyId + "/" + param.category).then((res) => {
            callback(res.data);
        })
    },
    //删除分类信息
    deleteClassify(param, callback) {
        axios.delete(this.mdBaseUrl + this.mdProMat + "/classify/del/" + param.id).then((res) => {
            callback(res.data);
        });
    },
    //添加分类信息
    addClassify(param, callback) {
        axios.request(
            {
                url: this.mdBaseUrl + this.mdProMat + "/classify/add",
                method: "post",
                data: param,
                headers: {
                    "Content-Type": "application/json;charset=UTF-8"
                }
            }
        ).then((res) => {
            callback(res.data)
        });
    },
    //搜索分类信息
    findClassify(param, callback) {
        axios.get(this.mdBaseUrl + this.mdProMat + "/classify/query/" + param).then((res) => {
            callback(res.data);
        })
    },
    //添加产品物料信息
    addProduct(param, callback) {
        axios.request(
            {
                url: this.mdBaseUrl + this.mdProMat + "/add/"+param.category,
                method: "post",
                data: param,
                headers: {
                    "Content-Type": "application/json;charset=UTF-8"
                }
            }
        ).then((res) => {
            callback(res.data)
        });
    },
    //修改产品物料信息
    updateProduct(param, callback) {
        axios.request(
            {
                url: this.mdBaseUrl + this.mdProMat + "/update/"+param.category,
                method: "put",
                data: param,
                headers: {
                    "Content-Type": "application/json;charset=UTF-8"
                }
            }
        ).then((res) => {
            callback(res.data)
        });
    },

};
export default mdAPI;
